﻿using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Collections.Generic;
using System.Reflection;

namespace Framework.Utils
{
    /// <summary>
    /// 反射工具
    /// </summary>
    public class ReflectUtils
    {

        /// <summary>
        /// 获取数据对象
        /// </summary>
        /// <param name="dic"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object Get(object obj, string key)
        {
            if (obj == null) { return null; }
            // 判断如果是词典
            var dic = obj as Dictionary<string, object>;
            if (dic != null) { return dic[key]; }
            // 获取类反射
            Type t = obj.GetType();
            FieldInfo fieldInfo = t.GetField(key);
            if (fieldInfo == null) { return null; }
            // 获取数据对象
            return fieldInfo.GetValue(obj);
        }


    }
}
